function vlcServer()
{
   server = document.location.href;
   exp = new RegExp("^http.[://][//][0-9a-zA-Z/.]{1,}[:]+[0-9]+[//]");
   return exp.exec(server);
}

function vlcCmd()
{
    this.baseUrl = function()
    {
        return vlcServer();
    }

    this.playlistClear = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_empty";        
        loadXMLDoc(url);
    }

    this.playFile = function(filename)
    {
        url = this.baseUrl()+"requests/status.xml?command=in_play&input="+filename;        
        loadXMLDoc(url);
    }

    this.play = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_play";
        loadXMLDoc(url);
    }

    this.pause = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_pause";
        loadXMLDoc(url);
    }

    this.stop = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_stop";
        loadXMLDoc(url);
    }

    this.toggelFullscreen = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=fullscreen";
        loadXMLDoc(url);
    }

    this.volumeSet = function(value)
    {
        value = value.replace("+", "%2B");
        url = this.baseUrl()+"requests/status.xml?command=volume&val="+value;
        xmlDoc = loadXMLDoc(url);

        status = new vlcStatus(xmlDoc);
        if (status.volume > 512) this.volumeSet("512");

        status.embedStatusTable("debug");
    }

    this.volumeUp = function()
    {
        this.volumeSet("%2B25");
    }

    this.volumeDown = function()
    {
        this.volumeSet('-25');
    }

    this.seek = function(value)
    {        
        value = String(value).replace("+", "%2B");
        url = this.baseUrl()+"requests/status.xml?command=seek&val="+value;
        xmlDoc = loadXMLDoc(url);

        status = new vlcStatus(xmlDoc);
        if (status.volume > 512) this.volumeSet("512");

        status.embedStatusTable("debug");
    }

    this.seekJumpTime = function(dir, h, m, s)
    {
        if ((dir  == null) || (dir  == "")) dir  = 0;
        if (dir < 0)
            value = "-";
        else
            value = "%2B";

        if ((undefined == h) || (h == "")) h = "0";
        if ((undefined == m) || (m == "")) m = "0";
        if ((undefined == s) || (s == "")) s = "0";

        value = String(value + h + "H:" + m + "M:" + s + "S");        
        this.seek(value);
    }

    this.jumpNext = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_next";
        loadXMLDoc(url);
    }

    this.jumpPrevious = function()
    {
        url = this.baseUrl()+"requests/status.xml?command=pl_previous";
        loadXMLDoc(url);
    }
}
